<template>
	<view class="animated fadeIn faster">
		<view class="px-3 mb-3 pt-2">
			<cc-newsTabs :tabArr="tabArr" @tabChange="tabChange"></cc-newsTabs>
		</view>
		
		<view class="px-3 pb-5">
			<view class="bg-fff rounded10 p-2 mb-2" v-for="error in list" :key="error.id">
				<view class="text-clamp-two font30 mb-2">{{error.content}}</view>
				<view class="d-flex d-flex-between d-flex-middle">
					<view class="d-flex font20 color999">
						<text>日期：</text>
						<text>{{error.practice_date}}</text>
					</view>
					<view class="d-flex d-flex-end">
						<view class="rewrite d-flex d-flex-center d-flex-middle mr-2" @click="rewrite(error)">重做</view>
						<view class="inspect d-flex d-flex-center d-flex-middle" @click="goWatch(error)">查看</view>
					</view>
				</view>
			</view>
		</view>
		<view class="load-more d-flex d-flex-center d-flex-column d-flex-middle">
			<image class="mb-2" v-if="loadingType == 2 && list.length == 0"
				src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/formal/images/empty.png"
				style="width: 198rpx;height: 128rpx;margin-top: 260rpx;"></image>
			<text>{{loadingType === 0 ? '上拉显示更多' : (loadingType === 1 ? '正在加载...' : '~ 没有更多数据了 ~')}}</text>
		</view>
		
		<!-- <view class="d-flex d-flex-center pb-5">
			<view class="bg-fff rounded60 d-flex d-flex-middle" style="padding: 20rpx 150rpx; color: #D43030;">
				<text class="iconfont icon-shanchu mr-1 font28"></text>
				<text>删除所有错题</text>
			</view>
		</view> -->
	</view>
</template>

<script>
	import { userApi } from '@/http/userApi.js'
	export default {
		data() {
			return {
				loadingType:1,
				tabId:'1',
				tabArr: [{
					name: '章节练习',
					id: '1'
				}, {
					name: '随机练习',
					id: '2'
				}],
				list:[]
			}
		},
		onReady() {
			this.getErrorsList()
		},
		onPullDownRefresh() {
			this.list = []
			this.getErrorsList()
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			tabChange(e){
				this.tabId = e==1?'2':'1'
				this.list = []
				this.getErrorsList()
			},
			getErrorsList(){
				let that = this
				uni.showLoading({
					title:'加载中...',
					mask:true
				})
				that.loadingType = 1
				userApi.errQuestion(that.tabId).then((res)=>{
					uni.hideLoading()
					that.loadingType = 2
					that.list = res.questions
				}).catch((e)=>{
					that.loadingType = 2
					uni.hideLoading()
				})
			},
			goWatch(error){
				return uni.navigateTo({
					url: `/subPages/topic/topic?topic=${encodeURIComponent(JSON.stringify(error))}`
				})
			},
			rewrite(error){
				return uni.navigateTo({
					url: `/subPages/reTopic/reTopic?topic=${encodeURIComponent(JSON.stringify(error))}`
				})
			},
			clearAll(){
				uni.showToast({
					title:'清除成功'
				})
			}
		}
	}
</script>

<style scoped>
.rewrite{
	width: 100rpx;
	height: 40rpx;
	border-radius: 50rpx;
	border: solid 1px #FFA18C;
	background-color: rgba(255, 87, 51, 0.3);
	color: #D43030;
	font-size: 24rpx;
}
.inspect{
	width: 100rpx;
	height: 40rpx;
	border-radius: 50rpx;
	border: solid 1px #3E8EFE;
	background-color: rgba(42, 130, 228, 0.2);
	color: #3E8EFE;
	font-size: 24rpx;
}
</style>
